import os
import logging
import time

# api_test_log_20210317.log

current_path = os.path.dirname(__file__)
log_output_path = os.path.join(current_path, '..', 'logs')


class LogUtils:
    def __init__(self, log_path=log_output_path):
        self.log_file_path = os.path.join(log_path, 'api_test_log_%s.log' % time.strftime('%Y%m%d'))
        self.logger = logging.getLogger('WX_Api_test_log')
        self.logger.setLevel(10)
        console_handler = logging.StreamHandler()
        file_handler = logging.FileHandler(self.log_file_path, 'a', encoding='utf-8')
        formatter = logging.Formatter("%(asctime)s__%(name)s__%(levelname)s__%(message)s")  # 格式对象
        console_handler.setFormatter(formatter)
        file_handler.setFormatter(formatter)

        self.logger.addHandler(console_handler)
        self.logger.addHandler(file_handler)

        console_handler.close()  # 关闭目的 防止日志重复
        file_handler.close()

    def get_logger(self):
        return self.logger


logger = LogUtils().get_logger()

if __name__ == '__main__':
    logger.info('执行接口测试用例开始!!!')
    logger.info('1234')
